from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime


class DeptResponse(BaseModel):
    id: Optional[int] = Field(None, description="事业部ID")
    dept_name: str = Field(..., description="事业部名称")
    dept_code: str = Field(..., description="事业部编码")
    descriptions: Optional[str] = Field(None, description="描述信息")
    status: Optional[bool] = Field(True, description="是否启用")
    parent_id: Optional[int] = Field(None, description="上级部门ID")
    parent_name: Optional[str] = Field(None, description="上级部门名称")
    parent_code: Optional[str] = Field(None, description="上级部门编码")
    manager_id: Optional[int] = Field(None, description="主管ID")
    manager_name: Optional[str] = Field(None, description="主管名称")
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")

    class Config:
        from_attributes = True


class DeptListResponse(BaseModel):
    total: int = Field(..., description="总数量")
    items: List[DeptResponse] = Field(..., description="事业部列表")
    page: int = Field(..., description="页码")
    size: int = Field(..., description="每页数量")
    pages: int = Field(..., description="总页数")


class DeptTreeNode(BaseModel):
    id: int
    dept_name: str
    dept_code: str
    status: Optional[bool] = True
    parent_id: Optional[int] = None
    manager_id: Optional[int] = None
    manager_name: Optional[str] = None
    children: List["DeptTreeNode"] = Field(default_factory=list)

    class Config:
        arbitrary_types_allowed = True


class DeptTreeResponse(BaseModel):
    items: List[DeptTreeNode]